﻿using System;
using TheBigB.JsonSerializerLite;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tester
{
	/// 
	/// Serializer extension tests.
	/// 
	/// Tests the extension functionality for the JsonSerializer
	/// 
	/// Changelog:
	///		2012-04-30
	///			- Initial tests
	///

	/// <summary>
	/// Serializer extension tests.
	/// </summary>
	[TestClass]
	public class SerializerExtensionTests
	{
		/// <summary>
		/// Tests an extension for the TestChildObject where the TestChildObject
		/// is provided as direct input
		/// </summary>
		[TestMethod]
		public void TestExtendedTypeAsInput()
		{
			TestChildObject input;
			string output, expected;

			// Create serializer instance and register extension
			JsonSerializer serializer = new JsonSerializer();
			serializer.Extenders += new TestExtension();

			input = new TestChildObject();
			expected = "{\"extension\":\"success\"}";
			output = serializer.Serialize(input);
			Assert.AreEqual(expected, output);
		}

		/// <summary>
		/// Tests an extension for the TestChildObject where the TestChildObject
		/// is provided as child of a TestObject instance
		/// </summary>
		[TestMethod]
		public void TestExtendedTypeAsChild()
		{
			TestObject input;
			string output, expected;

			// Create serializer instance and register extension
			JsonSerializer serializer = new JsonSerializer();
			serializer.Extenders += new TestExtension();

			input = new TestObject();
			input.childObject = new TestChildObject();
			expected = "{\"testIntArray\":[],\"testByte\":0,\"testShort\":0,\"testInt\":0,\"testLong\":0,\"testFloat\":0,\"testDouble\":0,\"testString\":\"\",\"embeddedObject\":null,\"childObject\":{\"extension\":\"success\"}}";
			output = serializer.Serialize(input);
			Assert.AreEqual(expected, output);
		}
	}
}
